package toster;

/**
 * Wrapper for permutations
 * @author Rcluster
 */

public class Perms {
    private int maxSize;
    private int[][] p;
    private int size;

    /**
     * Constructor that initiallizes all fields,  it sets the maxSize to the int
     * you give it and creates a new array to size maxSize
     * @param numPerms, the maxSize you want the array to be
     */
    public Perms(int numPerms) {
        maxSize = numPerms;
        p = new int[maxSize][];
        size = 0;
    }

    public Perms(int[][] in){
        this(in.length);
        for(int[] i:in)
            this.add(i);
    }

    /**
     * Adds a permutation to the array at the index size is at, starts at 0 and
     * increases size with every permutation added
     * @param perm, permutation you want added to the array
     */
    public void add(int[] perm) {
        p[size] = perm;
        size++;
    }

    /**
     * removes the permutation at the index you give it and decreases size
     * @param index, index of permutation you want removed
     */
    public void remove(int index) {
        p[index] = p[size - 1];
        size--;
        if (3*size < 2*p.length) {
            int[][] temp = new int[size][];
            for (int i = 0; i < size; i++) {
                temp[i] = p[i];
            }
            p = temp;
        }
    }

    /**
     * get all pemutations of the array list
     * @return, the array list
     */
    public int[][] getAll() {
        return p;
    }
    /**
     * returns a permutation at a particular index
     * @param index, index of the permutation you want returned
     * @return, permutation at the index you specified
     */
    public int[] get(int index) {
        return p[index];
    }

    /**
     * gets the size of the array
     * @return, the number of permutations in the array
     */
    public int size() { return size; }
}
